package App.controllertest;

import App.vo.DemoVo;
import com.alibaba.fastjson.JSON;
import simple.form.cache.Cache;
import simple.form.controller.BaseController;
import simple.form.controller.Request;
import simple.form.controller.Response;
import simple.form.controller.annotation.Controller;
import simple.form.controller.annotation.RequestMapping;
import simple.form.utils.QrcodeUtil;
import simple.form.utils.SafeConvertUtil;

import javax.imageio.ImageIO;
import java.io.IOException;

/**
 * Created by Administrator on 2017/2/23.
 */
@Controller
public class QrcodeController1 extends BaseController{

    @RequestMapping(url = "/test1",cacheKey =DemoVo.class)
    public void test(Request request, Response response) throws IOException {
        System.out.println("QrcodeController1.test");
        //1,初始化请求参数bean并解析
        DemoVo demoVo = new DemoVo(request);
        pareBean(demoVo);
        response.response("/test1");


    }

    @RequestMapping(url="/create_qrcode")
    public void create_qrcode(Request request, Response response) throws IOException {
        String content = SafeConvertUtil.toString(request.getRequest().getParameter("content"));
        response.getResponse().setContentType("image/jpeg");
        response.getResponse().setDateHeader("expries", -1);
        response.getResponse().setHeader("Cache-Control", "no-cache");
        response.getResponse().setHeader("Pragma", "no-cache");
        ImageIO.write(QrcodeUtil.create(content), "jpg", response.getResponse().getOutputStream());
    }
}
